//
//  PushAnimation.swift
//  jiahui
//
//  Created by 3tee on 2024/12/6.
//

import UIKit

class PushAnimation: NSObject,UIViewControllerAnimatedTransitioning{
    func transitionDuration(using transitionContext: (any UIViewControllerContextTransitioning)?) -> TimeInterval {
        return 0.5
    }
    
    func animateTransition(using transitionContext: any UIViewControllerContextTransitioning) {
        guard let toVC = transitionContext.viewController(forKey: .to),let fromVC = transitionContext.viewController(forKey: .from)else{
            return
        }
        //获取到容器的视图
        let containerView = transitionContext.containerView
        //添加ToVC
        containerView.addSubview(toVC.view)
        //初始化状态
        toVC.view.alpha = 0
        toVC.view.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
        //执行动画
        //UIView.animate(withDuration: transitionDuration(using: transitionContext)
        UIView.animate(withDuration: transitionDuration(using: transitionContext)) {
            toVC.view.alpha = 1.0
            toVC.view.transform = CGAffineTransform.identity
        } completion: { finished in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
        }

    }
    

}
